// 兼容IE

import Vue from 'vue'
// import 'normalize.css/normalize.css'// A modern alternative to CSS resets
// import 'font-awesome/css/font-awesome.min.css'
// import Element from 'element-ui'
// import 'element-ui/lib/theme-chalk/index.css'
// import '@/styles/element-variables.scss'
import '@/css/index.scss' // global css

import App from '../App'
import router from '../router/index'
import store from '../store/index'

// import i18n from '../lang/index' // Internationalization
// import '../icons/index' // icon
import '../errorLog'
// error log
import '../permission' // permission control
import initLogin from '../utils/initLogin'

// eslint-disable-next-line
import {
    Checkbox, CheckboxGroup,
    Loading, Popover, Tree, Message, Table, TableColumn, Pagination, Tooltip, Tag
    , Select, Option, Form, FormItem, DatePicker, Tabs, TabPane, Radio, RadioGroup, Alert
} from 'element-ui'
import { $x } from 'party_fe_component'

import debugInfo from 'party_fe_component/src/components/debugInfo'

Vue.prototype.$ELEMENT = { size: 'small' };

Vue.use(Checkbox).use(CheckboxGroup)
    .use(Loading).use(Popover).use(Tree).use(debugInfo).use(Table).use(TableColumn).use(Pagination).use(Tooltip).use(Tag)
    .use(Select).use(Option).use(Form).use(FormItem).use(DatePicker).use(Tabs).use(TabPane).use(Radio).use(RadioGroup).use(Alert)

// Vue.use(Element, {
//   size: 'medium', // set element-ui default size
//   i18n: (key, value) => i18n.t(key, value)
// })

Vue.prototype.$x = $x
Vue.prototype.$message = Message
Vue.config.productionTip = false

initLogin().then(appInfo => {
    if (appInfo.token) {
        store.dispatch('LoginByAccredit', appInfo)

        new Vue({
            el: '#app',
            router,
            store,
            // i18n,
            template: '<App/>',
            components: { App }
        })
    } else {
        $x.toast.error({
            message: '未获取到token',
            type: 'error',
            duration: 5 * 1000
        })
    }
})

/* IFDEBUG
// for debug(条件编译)
window._vue = Vue
window.router = router
window.store = store
window.$x =  $x
document.body.insertAdjacentHTML('afterBegin', '<i style="position:fixed;">DEV</i>')
FIDEBUG */

/* IFTRUE_isInTest */
// 测试环境下 Shift+双击 进入本地调试
document.addEventListener('dblclick', function (e) {
    if (e.shiftKey) {
        location = 'http://localhost:6767/#' + location.href.split('#')[1]
    }
})
/* FITRUE_isInTest */
